\chapter{Outcome}
We achieved all the compulsory features and most of the optional ones that were mentioned in the goals part.
The "PICycle"...
\begin{itemize}
\item has an on line adjustable wheel circumference
\item has an extra distance and av. speed counter/display (for one trip)
\item uses the sleep mode in order to be energy saving
\item stores data in eeprom before going to sleep (and restores it afterwards)
\item reads the tilt angle from an accelerometer (power estimation has numerical problems)
\end{itemize}

\section{Specifications}
\label{sec:outcomespecs}
As no high precision is needed the stored values are not of a high resolution. It is more important to prevent overflows with long distances and times.
\begin{itemize}
\item speed from $0$ to over $100 \frac{km} h$, theoretical limit is $655,35 \frac{km} h$ (on very high speeds the calculating becomes to slow)
\item distances from $0$ to $99.999,99$ $km$ with a resolution of 10 meters (internal maximum is $42.949.672,95$ $km$)
\item time from $0$ to $99.999,99$ $h$ with resolution of 36 seconds (internal maximum is $42.949.672,95$ $h$)
\end{itemize}
\section{Sensors}
For the detection of the wheel rotation the sub-miniature high sensitivity photo interrupter ITR8307 was used. It is a reflective sensor consisting of an infrared emitting diode and NPN photo transistor. The transistor responds to the radiation emitted by the diode when a reflective surface is in the field of view of the detector. Thus a black sign on a metal wheel will generate a pulse. In a real application a reflective (white) sign would give a signal on the black wheel of the bike.

The tilt sensor used was the Low-cost $\pm$ 2 \textit{g} dual-axis accelerometer with duty cycle output ADXL202E, which is a complete 2-axis accelerometer with a digital output. It measures accelerations with a full-scale range of $\pm$ 2 \textit{g}. It can measure both dynamic acceleration such as vibration, and static acceleration like gravity. The outputs are analog voltage or digital signals whose duty cycles are proportional to acceleration. In the current project the $X_{FILT}$ pin was used.

\section{Hardware}
The prototype board is used for the processing of the sensor data. A modification was necessary to use the "capture" feature of the microcontroller. As the program part became big and processing speed was useful an 20MHz clocked PIC16F876A was used.

\section{Software}
The speed sensor is connected to the CCP1 port. The capture feature is used to get the TMR1 value when a pulse arrives. The "switching" between pulse counting and time counting as planned in the beginning was not necessary as we only deal with slow frequencies (max. ca. 20Hz).
The tilt angle is read from the accelerometer via the AN0 port and converted (10bit).

The program is implemented in parts where flags are checked and actions taken (like going to sleep, calculating new values and displaying them) and a state machine that implements the user interface and decides what is displayed. Other actions are executed every cycle like the checking of the button positive flanks.
The flags are partly set in the interrupt routine that keeps track of overflows of timer 1 and saves the captured values. The others (like \textit{updateScreen}) are set in the main routine. 

In this way all the interrupt service routine is kept small and all the heavy calculations (e.g. divisions to calculate speed, average speed and the power) are done in the main program.

\section{User Interface}
The user interface implements different states:
\begin{figure}[htb]
\begin{center}
\ifpdf
	\includegraphics[scale=0.18]{img/display.jpg}
\else
%	\includegraphics[scale=0.18]{img/display.jpg}
\fi
\caption{Display showing the actual speed and the weight settings menu}
\label{fig:display}
\end{center}
\end{figure}
\begin{enumerate}
\item display distance 1 (trip distance)
\item display time 1 (time of the trip)
\item display average speed 1 (for the trip)
\item display distance 2 (overall distance)
\item display time 2 (overall time)
\item display average speed 2 (overall)
\item display the actual estimated power 
\item display the estimated burnt energy
\item change the wheel circumference (in millimeters)
\item change the weight of biker and bicycle
\end{enumerate}
\begin{figure}[htb]
\begin{center}
\ifpdf
	\includegraphics[scale=0.17]{img/buttons.jpg}
\else
%	\includegraphics[scale=0.17]{img/buttons.jpg}
\fi
\caption{The buttons and their meaning}
\label{fig:buttons}
\end{center}
\end{figure}
The user can cycle through these states with a button. Another button is used in the "display" states to reset the shown value. In the settings this is the "set" button. The arrow buttons are only available in the settings to change the position of the cursor (left-right), and increase (up) or decrease (down) the value (see figure \ref{fig:buttons}). 







